/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.muni.fi.pa165.transfers;

import cz.muni.fi.pa165.dto.CustomerDTO;
import cz.muni.fi.pa165.dto.EmployeeDTO;
import cz.muni.fi.pa165.entity.Customer;
import cz.muni.fi.pa165.entity.Employee;
import java.util.Date;

/**
 * Class provides converting between Employee entity and DTO
 * 
 * @author <a href="mailto:vramik at redhat.com">Vlastislav Ramik</a>
 */
public class EmployeeT {

    public static EmployeeDTO entityToDTO(Employee employee){
        if (employee == null) {
            return null;
        }
        
        EmployeeDTO employeeDTO = new EmployeeDTO();
        
        employeeDTO.setId(employee.getId());
        if (employee.getBirthDate() != null) {
            employeeDTO.setBirthDate(new Date(employee.getBirthDate().getTime()));
        }
        employeeDTO.setName(employee.getName());
                
        return employeeDTO;        
    }
    
    public static Employee dTOtoEntity(EmployeeDTO employeeDTO){
        if (employeeDTO == null) {
            return null;
        }
        
        Employee employee = new Employee();
        
        employee.setId(employeeDTO.getId());
        if (employeeDTO.getBirthDate() != null) {
            employee.setBirthDate(new Date(employeeDTO.getBirthDate().getTime()));
        }
        employee.setName(employeeDTO.getName());
                
        return employee;         
    }    
}
